package com.hankol.message.viewmodel

import androidx.fragment.app.FragmentManager
import androidx.lifecycle.MutableLiveData
import com.baselibrary.base.BasicListBean
import com.baselibrary.base.mvvm.BaseViewModel
import com.hankol.message.R
import com.hankol.message.bean.*
import com.hankol.message.fragment.MyConversationListFragment
import com.hankol.message.imConfig.CustomConversationProvider
import com.hankol.message.respository.MessageRequestManager
import io.rong.imkit.RongIM


/**首页--tab 消息
 * @author: merbng
 * @time: 2021/10/15 10:05
 * @description:
 */
class HomeMessageViewModel : BaseViewModel() {
    var dataListLD: MutableLiveData<BasicListBean<LikeAndCollectBean>> = MutableLiveData()
    var broadcastDataListLD: MutableLiveData<BasicListBean<BroadcastMsgBean>> = MutableLiveData()
    var commentMedataListLD: MutableLiveData<BasicListBean<CommentMeBean>> = MutableLiveData()
    var broadcastReadLD: MutableLiveData<Boolean> = MutableLiveData()
    var unReadCntLD: MutableLiveData<UnReadCntBean> = MutableLiveData()
    var sysMsgLD: MutableLiveData<List<GetSysMsgListBean>> = MutableLiveData()

    fun initConversation(fragmentManager: FragmentManager): MyConversationListFragment {
        RongIM.getInstance().registerConversationTemplate(CustomConversationProvider())
        val conversationListFragment = MyConversationListFragment()
        val transaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.fl_friendsList, conversationListFragment);
        transaction.commit();
        return conversationListFragment
    }

    //点赞和收藏 列表
    fun reqLikeAndCollectList(page: Int) {
        MessageRequestManager.getInstance().reqLikeAndCollectList(page, dataListLD)
    }

    //评论我的 列表
    fun reqCommentMeList(page: Int) {
        MessageRequestManager.getInstance().reqCommentMeList(page, commentMedataListLD)
    }

    //系统消息 列表
    fun reqSystemMsgList(msgPushTypeId: Int, cursor: String) {
        MessageRequestManager.getInstance().reqSystemMsgList(msgPushTypeId, cursor, broadcastDataListLD)
    }

    //广播-设置消息为已读
    fun reqBroadcastRead() {
        MessageRequestManager.getInstance().reqBroadcastRead(broadcastReadLD)
    }

    //评论我的列表、赞和收藏列表、新增粉丝列表，3个接口的未读数统计
    fun reqUnReadCnt() {
        MessageRequestManager.getInstance().reqUnReadCnt(unReadCntLD)
    }

    //系统消息类型列表
    fun reqGetSysMsgList() {
        MessageRequestManager.getInstance().reqGetSysMsgList(sysMsgLD)
    }
}